#include <bits/stdc++.h>
// 2025/02/06
// tag:
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

#define int long long

int n, feel[100001], l[100001], r[100001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true) {
        cin >> n;
        if (n == 0)
            return 0;
        for (int i = 1; i <= n; i++)
            cin >> feel[i];
        stack<int> st;
        for (int i = 1; i <= n; i++) {
            r[i] = n + 1;
            while (!st.empty() && feel[st.top()] > feel[i])
                r[st.top()] = i, st.pop();
            st.push(i);
        }
        st = stack<int>();
        for (int i = n; i >= 1; i--) {
            l[i] = 0;
            while (!st.empty() && feel[st.top()] > feel[i])
                l[st.top()] = i, st.pop();
            st.push(i);
        }
        int ans = 0;
        for (int i = 1; i <= n; i++)
            ans = max(ans, (r[i] - l[i] - 1) * feel[i]);
        cout << ans << endl;
    }
    return 0;
}